home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 October: Mac OS SDK / Dev.CD Oct 00 SDK1.toast / Development Kits / Mac OS / Appearance SDK 1.0.4 / Appearance Sample Code / Source / ClassicPane.cp < prev    next >
Encoding:
Text File  |  1999-07-16  |  8.4 KB  |  299 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        ClassicPane.cp
  3.  
  4.     Contains:    Class to drive our classic pane, showing new versions of old favorites.
  5.  
  6.     Version:    Appearance 1.0 SDK
  7.  
  8.     Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                Edward Voas
  13.  
  14.         Other Contact:        7 of 9, Borg Collective
  15.  
  16.         Technology:            OS Technologies Group
  17.  
  18.     Writers:
  19.  
  20.         (MAA)    Matt Ackeret
  21.         (edv)    Ed Voas
  22.  
  23.     Change History (most recent first):
  24.  
  25.          <3>    11/17/97    MAA        fix error wrt. pagedown in the vertical scrollbar
  26.          <2>    10/28/97    edv        Use Radio Group control!
  27.          <1>     9/11/97    edv        First checked in.
  28. */
  29.  
  30. #include "ClassicPane.h"
  31. #include "Appearance.h"
  32. #include "AppearanceHelpers.h"
  33. #include "UDialogUtils.h"
  34.  
  35. #define MIN( a, b )        ( ( (a) < (b) ) ? (a) : (b) )
  36. #define MAX( a, b )        ( ( (a) > (b) ) ? (a) : (b) )
  37.  
  38. enum
  39. {
  40.     kEngageButton             = 1,
  41.     kMakeItSoButton            = 2,
  42.     kEjectCoreButton        = 3,
  43.     kRaiseShieldsButton        = 4,
  44.     kUserItem                = 6,
  45.     kVerticalScrollBar        = 7,
  46.     kHorizontalScrollBar    = 8,
  47.     kTuneUpCheckBox         = 9,
  48.     kConstrictorsCheckBox    = 10,
  49.     kIntermixCheckBox        = 11,
  50.     kRadioGroup                = 12,
  51.     kDessertRadio            = 13,
  52.     kFloorWaxRadio            = 14,
  53.     kBothButton                = 15
  54. };
  55.  
  56. enum
  57. {
  58.     kConstrictorsMask        = 1,
  59.     kIntermixMask            = 2,
  60.     kAllCheckMask            = 3
  61. };
  62.  
  63. ControlActionUPP    ClassicPane::fScrollBarProc = NewControlActionProc( ClassicPane::ScrollingFeedbackProc );
  64. ControlUserPaneDrawUPP    ClassicPane::fDrawProc = NewControlActionProc( ClassicPane::DrawPictureProc );
  65.  
  66. ClassicPane::ClassicPane( DialogPtr dialog, SInt16 items ) : MegaPane( dialog, items )
  67. {
  68.     ControlHandle        control;
  69.     
  70.     AppendDialogItemList( dialog, 6003, overlayDITL );
  71.  
  72.     GetDialogItemAsControl( dialog, kTuneUpCheckBox + items, &control );
  73.     SetControlMaximum( control, 2 );
  74.  
  75.     GetDialogItemAsControl( dialog, kMakeItSoButton + items, &control );
  76.     SetPushButtonDefaultState( control, true );
  77.     
  78.     GetDialogItemAsControl( dialog, kEjectCoreButton + items, &control );
  79.     DeactivateControl( control );
  80.  
  81.     GetDialogItemAsControl( dialog, items + kHorizontalScrollBar, &fHorizontalScrollBar );
  82.     GetDialogItemAsControl( dialog, items + kVerticalScrollBar, &fVerticalScrollBar );
  83.     
  84.     SetControlReference( fHorizontalScrollBar, (long)this );
  85.     SetControlReference( fVerticalScrollBar, (long)this );
  86.     
  87.     fPictOffset.h = 0;
  88.     fPictOffset.v = 0;
  89.     
  90.     fPicture = GetPicture( 6003 );
  91.     fPictWidth = (**fPicture).picFrame.right - (**fPicture).picFrame.left;
  92.     fPictHeight = (**fPicture).picFrame.bottom - (**fPicture).picFrame.top;
  93.     
  94.     GetDialogItemAsControl( dialog, items + kUserItem, &fUserItem );
  95.     SetControlReference( fUserItem, (long)this );
  96.     SetControlData( fUserItem, 0, kControlUserPaneDrawProcTag, sizeof( fDrawProc ), (Ptr)&fDrawProc );
  97.  
  98.     fUserItemHeight = (**fUserItem).contrlRect.bottom - (**fUserItem).contrlRect.top;
  99.     fUserItemWidth = (**fUserItem).contrlRect.right - (**fUserItem).contrlRect.left;
  100.     
  101.     SetControlMaximum( fHorizontalScrollBar, fPictWidth - fUserItemWidth );
  102.     SetControlMaximum( fVerticalScrollBar, fPictHeight - fUserItemHeight );
  103.     
  104.     SetControlAction( fHorizontalScrollBar, fScrollBarProc );
  105.     SetControlAction( fVerticalScrollBar, fScrollBarProc );
  106.     
  107.     GetDialogItemAsControl( dialog, fOrigItems + kDessertRadio, &control );
  108.     SetControlMaximum( control, kControlCheckBoxMixedValue );
  109.     GetDialogItemAsControl( dialog, fOrigItems + kFloorWaxRadio, &control );
  110.     SetControlMaximum( control, kControlCheckBoxMixedValue );
  111. }
  112.  
  113. ClassicPane::~ClassicPane()
  114. {
  115.     ShortenDITL( fDialog, CountDITL( fDialog ) - fOrigItems );
  116. }
  117.  
  118. void
  119. ClassicPane::ItemHit( SInt16 item )
  120. {
  121.     SInt16            localItem;
  122.     ControlHandle    control;
  123.     SInt16            value;
  124.     Boolean            syncCheck = false;
  125.     SInt16            checkValues = 0;
  126.     
  127.     localItem = item - fOrigItems;
  128.     
  129.     switch ( localItem )
  130.     {
  131.         case kTuneUpCheckBox:
  132.             GetDialogItemAsControl( fDialog, item, &control );
  133.             value = GetControlValue( control );
  134.             
  135.             if ( value == kControlCheckBoxUncheckedValue )
  136.             {
  137.                 SetControlValue( control, kControlCheckBoxCheckedValue );
  138.                 GetDialogItemAsControl( fDialog, fOrigItems + kConstrictorsCheckBox, &control );
  139.                 SetControlValue( control, kControlCheckBoxCheckedValue );
  140.                 GetDialogItemAsControl( fDialog, fOrigItems + kIntermixCheckBox, &control );
  141.                 SetControlValue( control, kControlCheckBoxCheckedValue );
  142.             }
  143.             else if ( value == kControlCheckBoxCheckedValue )
  144.             {
  145.                 SetControlValue( control, kControlCheckBoxUncheckedValue );
  146.                 GetDialogItemAsControl( fDialog, fOrigItems + kConstrictorsCheckBox, &control );
  147.                 SetControlValue( control, kControlCheckBoxUncheckedValue );
  148.                 GetDialogItemAsControl( fDialog, fOrigItems + kIntermixCheckBox, &control );
  149.                 SetControlValue( control, kControlCheckBoxUncheckedValue );
  150.             }
  151.             else if ( value == kControlCheckBoxMixedValue )
  152.             {
  153.                 SetControlValue( control, kControlCheckBoxCheckedValue );
  154.                 GetDialogItemAsControl( fDialog, fOrigItems + kConstrictorsCheckBox, &control );
  155.                 SetControlValue( control, kControlCheckBoxCheckedValue );
  156.                 GetDialogItemAsControl( fDialog, fOrigItems + kIntermixCheckBox, &control );
  157.                 SetControlValue( control, kControlCheckBoxCheckedValue );
  158.             }
  159.             break;
  160.             
  161.         case kConstrictorsCheckBox:
  162.         case kIntermixCheckBox:
  163.             UDialogUtils::ToggleCheckBox( fDialog, item );
  164.             GetDialogItemAsControl( fDialog, fOrigItems + kConstrictorsCheckBox, &control );
  165.  
  166.             if ( GetControlValue( control ) )
  167.                 checkValues |= kConstrictorsMask;
  168.             else
  169.                 checkValues &= ~kConstrictorsMask;
  170.             
  171.             GetDialogItemAsControl( fDialog, fOrigItems + kIntermixCheckBox, &control );
  172.  
  173.             if ( GetControlValue( control ) )
  174.                 checkValues |= kIntermixMask;
  175.             else
  176.                 checkValues &= ~kIntermixMask;
  177.             
  178.             syncCheck = true;
  179.             break;
  180.         
  181.         case kBothButton:
  182.             GetDialogItemAsControl( fDialog, fOrigItems + kDessertRadio, &control );
  183.             SetControlValue( control, kControlCheckBoxMixedValue );
  184.             GetDialogItemAsControl( fDialog, fOrigItems + kFloorWaxRadio, &control );
  185.             SetControlValue( control, kControlCheckBoxMixedValue );
  186.             break;
  187.     }
  188.     
  189.     if ( syncCheck )
  190.     {
  191.         GetDialogItemAsControl( fDialog, fOrigItems + kTuneUpCheckBox, &control );
  192.  
  193.         if ( checkValues == 0 )
  194.             SetControlValue( control, kControlCheckBoxUncheckedValue );
  195.         else if ( checkValues == kAllCheckMask )
  196.             SetControlValue( control, kControlCheckBoxCheckedValue );
  197.         else
  198.             SetControlValue( control, kControlCheckBoxMixedValue );
  199.     }
  200. }
  201.  
  202. pascal void
  203. ClassicPane::DrawPictureProc( ControlHandle control, SInt16 part )
  204. {
  205.     #pragma unused( part )
  206.     
  207.     Rect            bounds;
  208.     RgnHandle        saveClip;
  209.     ClassicPane*    pane;
  210.     
  211.     pane = (ClassicPane*)GetControlReference( control );
  212.     bounds = (**control).contrlRect;
  213.     
  214.     FrameRect( &bounds );
  215.     InsetRect( &bounds, 1, 1 );
  216.     
  217.     saveClip = NewRgn();
  218.     GetClip( saveClip );
  219.     
  220.     ClipRect( &bounds );
  221.  
  222.     bounds.top -= pane->fPictOffset.v;
  223.     bounds.left -= pane->fPictOffset.h;
  224.     bounds.bottom = bounds.top + pane->fPictHeight;
  225.     bounds.right = bounds.left + pane->fPictWidth;
  226.     
  227.     DrawPicture( pane->fPicture, &bounds );
  228.     
  229.     SetClip( saveClip );
  230.     DisposeRgn( saveClip );
  231. }
  232.  
  233. pascal void
  234. ClassicPane::ScrollingFeedbackProc( ControlHandle control, SInt16 part )
  235. {
  236.     SInt16            startValue, delta, min, max;
  237.     ClassicPane*    pane;
  238.     
  239.     pane = (ClassicPane*)GetControlReference( control );
  240.  
  241.     startValue = GetControlValue( control );
  242.     min = GetControlMinimum( control );
  243.     max = GetControlMaximum( control );
  244.     
  245.     delta = 0;
  246.     
  247.     switch ( part )
  248.     {
  249.         case kControlUpButtonPart:
  250.             if ( startValue > min )
  251.                 delta = MAX( -5, min - startValue );
  252.             break;
  253.         
  254.         case kControlDownButtonPart:
  255.             if ( startValue < max )
  256.                 delta = MIN( 5, max - startValue );
  257.             break;
  258.         
  259.         case kControlPageUpPart:
  260.             if ( startValue > min )
  261.                 if ( control == pane->fHorizontalScrollBar )
  262.                     delta = MAX( -(pane->fUserItemWidth - 1), min - startValue );
  263.                 else
  264.                     delta = MAX( -(pane->fUserItemHeight - 1), min - startValue );
  265.             break;
  266.         
  267.         case kControlPageDownPart:
  268.             if ( startValue < max )
  269.                 if ( control == pane->fHorizontalScrollBar )
  270.                     delta = MIN( pane->fUserItemWidth - 1, max - startValue );
  271.                 else
  272.                     delta = MAX( -(pane->fUserItemHeight - 1), max - startValue );
  273.             break;
  274.     }
  275.  
  276.     if ( delta )
  277.     {
  278.         SetControlValue( control, startValue + delta );
  279.         if ( control == pane->fHorizontalScrollBar )
  280.             pane->fPictOffset.h += delta;
  281.         if ( control == pane->fVerticalScrollBar )
  282.             pane->fPictOffset.v += delta;
  283.         
  284.             // pretty inefficient scrolling here, but you get the point.
  285.             
  286.         DrawOneControl( pane->fUserItem );
  287.     }
  288.     else if ( part == kControlIndicatorPart )
  289.     {
  290.         if ( control == pane->fHorizontalScrollBar )
  291.             pane->fPictOffset.h = startValue - min;
  292.             
  293.         if ( control == pane->fVerticalScrollBar )
  294.             pane->fPictOffset.v = startValue - min;
  295.  
  296.         DrawOneControl( pane->fUserItem );
  297.     }
  298. }
  299.